﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {

        class QuickSort
        {
            public static
             void to_sort(double[] mas, long first, long last)
            {
                double p = mas[(last - first) / 2 + first];
                double temp;
                long i = first, j = last;
                while (i <= j)
                {
                    while (mas[i] < p && i <= last) ++i;
                    while (mas[j] > p && j >= first) --j;
                    if (i <= j)
                    {
                        temp = mas[i];
                        mas[i] = mas[j];
                        mas[j] = temp;
                        ++i; --j;
                    }
                }
                if (j > first) to_sort(mas, first, j);
                if (i < last) to_sort(mas, i, last);
            }
        }

        class Test
        {
            static void Main(string[] n)
            {
                double[] mas = new double[50];
                //заполняем массив случайными числами
                Random chislo = new Random();
                for (int i = 0; i < mas.Length; ++i)
                { mas[i] = chislo.Next(1, 101); }
                System.Console.WriteLine("\nStarting array:");
                foreach (double x in mas)
                {
                    System.Console.Write(x + " ");
                }
                //сортировка
                QuickSort.to_sort(mas, 0, mas.Length - 1);
                System.Console.WriteLine("\n\nArray after sorting:");
                foreach (double x in mas)
                {
                    System.Console.Write(x + " ");
                }
                Console.Read();
            }

        }
    }
}